package com.cloud.freeflow.api.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.cloud.freeflow.api.entity.ProcTransDef;
import com.cloud.freeflow.common.utils.BaseMapperHelper;

public interface ProcTransDefMapper extends BaseMapperHelper<ProcTransDef> {

	@Select("select a.trans_id, a.from_act, a.to_act, a.proc_def_id, a.trans_name, b.act_def_name from_act_name, c.act_def_name to_act_name from proc_trans_def a left join proc_act_def b on a.from_act = b.act_def_id left join proc_act_def c on a.to_act = c.act_def_id where a.proc_def_id = #{procDefId} and a.delete_flag = 0")
	@Results({ @Result(property = "transId", column = "trans_id", javaType = Long.class),
			@Result(property = "fromAct", column = "from_act", javaType = Long.class),
			@Result(property = "toAct", column = "to_act", javaType = Long.class),
			@Result(property = "procDefId", column = "proc_def_id", javaType = Long.class),
			@Result(property = "transName", column = "trans_name", javaType = String.class),
			@Result(property = "fromActName", column = "from_act_name", javaType = String.class),
			@Result(property = "toActName", column = "to_act_name", javaType = String.class) })
	List<ProcTransDef> searchProcTransByProcId(@Param("procDefId") Long procDefId);

	@Select("select a.trans_id, a.from_act, a.to_act, a.trans_name, a.filter_sql, b.act_def_name from_act_name, c.act_def_name to_act_name from proc_trans_def a left join proc_act_def b on a.from_act = b.act_def_id left join proc_act_def c on a.to_act = c.act_def_id where a.trans_id = #{transId}")
	@Results({ @Result(property = "transId", column = "trans_id", javaType = Long.class),
			@Result(property = "fromAct", column = "from_act", javaType = Long.class),
			@Result(property = "toAct", column = "to_act", javaType = Long.class),
			@Result(property = "transName", column = "trans_name", javaType = String.class),
			@Result(property = "filterSql", column = "filter_sql", javaType = String.class),
			@Result(property = "fromActName", column = "from_act_name", javaType = String.class),
			@Result(property = "toActName", column = "to_act_name", javaType = String.class) })
	ProcTransDef load(@Param("transId") Long id);
}